#!/bin/sh
SOLR_URL="http://localhost:8080/solr/update"
EXIST_URL="http://localhost:8080/orbeon/exist/rest/db/numishare"
#grab EAD files and index into solr
curl $EXIST_URL/ead | grep -o \"[^\.]*\.xml\" | sed s/\"//g > files.list;
for i in `cat files.list`; 
	do curl -o `basename $i` -s $EXIST_URL/ead/`basename $i`;
	java -jar saxon/saxon9.jar -xi:on -s `basename $i` -xsl:../cocoon/xslt/ead_to_solr.xsl > site_index/add_`basename $i`;
	rm $i; 
done
rm files.list;

#grab VRA files and index into solr
curl $EXIST_URL/vra | grep -o \"[^\.]*\.xml\" | sed s/\"//g > files.list;
for i in `cat files.list`; 
	do curl -o `basename $i` -s $EXIST_URL/vra/`basename $i`;
	java -jar saxon/saxon9.jar -xi:on -s `basename $i` -xsl:../cocoon/xslt/vra_to_solr.xsl > site_index/add_`basename $i`;
	rm $i; 
done
rm files.list;

SOLR_FILES="site_index/add_*.xml"

for f in $SOLR_FILES; do
  echo Posting file $f to $SOLR_URL
  curl $SOLR_URL --data-binary @$f -H 'Content-type:text/xml; charset=utf-8' 
  echo
done

#send the commit command to make sure all the changes are flushed and visible
curl $SOLR_URL --data-binary '<commit/>' -H 'Content-type:text/xml; charset=utf-8'
echo
